var provider = null;
var goods = null;

$("#providerconfirm").click(
		function() {
			var obj = $("#provider").val();
			if (obj == "add") { // 添加品种（关联供应商）的选择按钮
				var id = getSelectedNo("#providerList", "id");
				if (id == null) {
					alert("id	空")
					return;
				}
				$.post("/Medical_Instrument/supplierbreed/getsupplierallstaff",
						"id=" + id, function(object) {
							object = eval("(" + object + ")");
							$("#enterpriseName").val(object.enterpriseName); // 放入供应商名称

							var str = "";
							$.each(object.suppeoList, function(i, item) {
								str += "<option value=" + item.supplierPeopleId
										+ ">" + item.name + "</option>";
							});
							$("#people").children("option").remove();
							$("#people").append(str);

							$('#providerlist').map(function() {
								if (!$(this).is(":hidden")) {
									$(this).modal('hide');
								}
							});
						});
			} else if (obj == "query") { // 查询条件按钮
				var id = getSelectedNo("#providerList", "id");
				if (id == null) {
					alert("id	空")
					return;
				}
			}
		});

$("#goodsconfirm")
		.click(
				function() {
					var str = $("#choiceDML").val();
					if (str == "add") {// 添加品种（关联供应商）的选择按钮
						var id = getSelectedNo("#choice", "id");
						if (id == null) {
							alert("id	空")
							return;
						}
						$("#sublist").dataTable().fnDestroy();
						$("#sublist")
								.dataTable(
										{
											"processing" : true,
											"serverSide" : false,
											"paginationType" : "full_numbers",
											"ajax" : "/Medical_Instrument/supplierbreed/getvarietybyid?id="+id,
											"aaSorting" : [ [ 0, "desc" ] ], 
											"aoColumnDefs" : [ {
												"orderable" : false,
												"aTargets" : [ 1, 2 ]
											} ],
											"columns" : [ {
												"data" : "varietyName", // 品名
												"defaultContent" : ""
											}, {
												"data" : "specification", // 规格
												"defaultContent" : ""
											}, {
												"data" : "unit", // 单位
												"defaultContent" : ""
											}, {
												"data" : "manufacturer", // 生产厂家
												"defaultContent" : ""
											}, {
												"data" : "ingredient", // 备注
												"defaultContent" : ""
											} ]
										});
						$('#productadd').map(function() {
							if (!$(this).is(":hidden")) {
								$(this).modal('hide');
							}
						});
					} else if (str == "query") {// 查询条件按钮
						var id = getSelectedNo("#choice", "id");
						if (id == null) {
							alert("id	空")
							return;
						}
					}
				});

// 判断当前有没选中行
function getSelectedNo(obj, info) {
	var object = null;
	$(obj + ">tbody").find("tr").each(function() {
		if ($(this).hasClass('selected')) {
			if (info == "id") {
				object = $(this).children("td").eq(0).text();
			} else {
				object = $(this);
			}
		}
	});
	return object;
}